package com.xl;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.ftp.Ftp;
import com.xl.ftp.pool.FtpClientDataSource;
import com.xl.ftp.pool.FtpClientPool;
import com.xl.ftp.proxy.IFtpHandler;
import org.apache.commons.pool2.ObjectPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@SpringBootApplication
public class FtpPoolApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(FtpPoolApplication.class, args);
    }

    //注入FTP连接池对象,通过此对象可以获取FTP操作对象
    @Autowired
    private FtpClientDataSource dataSource;


    @Override
    public void run(ApplicationArguments args) {
        //测试代码
        Runnable runnable=()->{
           while(true){
               IFtpHandler ftpClientHandler = dataSource.getFtpClientHandler();
               List<String> ls = ftpClientHandler.ls("/");
               for (String l : ls) {
                   System.out.println(l);
               }
               System.out.println(Thread.currentThread().getName()+"out print=#");

           }
        };
        new Thread(runnable,"my-thread1").start();
        new Thread(runnable,"my-thread2").start();
        new Thread(runnable,"my-thread3").start();
    }
}
